<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <ui:composition template="layout.xhtml">

        <ui:define name="title">
            Protocolo
            <script>
                function title() {
                    document.getElementById('protocolo').className='selected';
                }
                window.onload=title;
            </script>
        </ui:define>

        <ui:define name="content">
            <h:form id="pesquisarProtocoForm">
                <div class="row">
                    <div class="column2">
                        <p:menu  >
                            <p:submenu label="Protocolo">
                                <p:menuitem url="criarProtocolo.xhtml" value="Novo Protocolo" />
                                <p:menuitem url="pesquisarProtocolo.xhtml" value="Pesquisar" rendered="false" />
                            </p:submenu>
                            <p:submenu label="Trâmite">
                                <p:menuitem url="criarTramite.xhtml" value="Cadastrar" />
                                <p:menuitem url="pesquisarTramite.xhtml" value="Pesquisar" />
                            </p:submenu>

                        </p:menu>
                    </div>
                    <div class="column10">


                        <p:messages id="pesquisarProtocoMessages" autoUpdate="true" />

                        <p:fieldset legend="Filtros" id="pesquisarProtocoPanel" 
                                    styleClass="column12" >

                            <f:validateBean disabled="true">
                                <div class="row">
                                    <div class="column1">
                                        <p:outputLabel value="Tipo" for="tipoProtocoloSelectOneMenu" />
                                    </div>
                                    <div class="column3">
                                        <p:selectOneMenu id="tipoProtocoloSelectOneMenu"
                                                         value="#{ managerPesquisarProtocolo.protocoloPesquisar.tipoProtocolo }">
                                            <f:selectItems value="#{ enums.tiposProtocolos() }" />
                                        </p:selectOneMenu>
                                    </div>                            

                                    <div class="column2">
                                        <p:outputLabel value="Código" for="codigoInputText" />
                                    </div>
                                    <div class="column3">
                                        <p:inputText id="codigoInputText" value="#{ managerPesquisarProtocolo.protocoloPesquisar.id }"/>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="column1">
                                        <p:outputLabel value="Data" for="nomeInputText" />
                                    </div>
                                    <div class="column3">
                                        <p:calendar id="dataVigorCalendar" value="#{ managerPesquisarProtocolo.protocoloPesquisar.dataCadastro }"
                                                    showOn="button" pattern="dd/MM/yyyy" locale="pt" navigator="true" />
                                    </div>

                                    <div class="column2">
                                        <p:outputLabel value="Cliente" for="nomeInputText" />
                                    </div>
                                    <div class="column5">
                                        <p:inputText id="nomeInputText" value="#{ managerPesquisarProtocolo.protocoloPesquisar.cliente.nome }"/>
                                    </div>
                                </div>
                            </f:validateBean>
                        </p:fieldset>

                        <div class="buttonAction">
                            <p:commandButton
                                id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search" oncomplete="widthFix();"
                                styleClass="ui-priority-primary"
                                update="@form" actionListener="#{ managerPesquisarProtocolo.pesquisar() }" />
                            <p:commandButton value="Limpar" icon="ui-icon-close" update="@form" oncomplete="widthFix();"
                                             actionListener="#{ managerPesquisarProtocolo.limpar() }" />
                        </div>

                        <p:fieldset legend="Resultado" styleClass="column12" >
                            <p:dataTable id="protocolosDataTable" var="protocolo" value="#{ managerPesquisarProtocolo.protocolos }"
                                         rows="5" paginator="true" paginatorPosition="bottom" emptyMessage="Nenhum protocolo encontrado">

                                <p:column headerText="Opções" width="10%">
                                    <div class="options3">
                                        <p:button
                                            title="Editar" href="criarProtocolo.xhtml?protocoloId=#{ protocolo.id }"
                                            icon="ui-icon-pencil"/>
                                        <p:button
                                            title="Visualizar" href="visualizarProtocolo.xhtml?protocoloId=#{ protocolo.id }"
                                            icon="ui-icon-search"/>
                                        <p:commandButton title="Excluir" oncomplete="dialogApagar.show()" icon="ui-icon-trash">
                                            <f:setPropertyActionListener target="#{ managerPesquisarProtocolo.protocoloDeletar }" value="#{ protocolo }" />
                                        </p:commandButton>
                                    </div>
                                </p:column>

                                <p:column headerText="Código" width="10%">
                                    <h:outputText value="#{ protocolo.id }" />
                                </p:column>
                                <p:column headerText="Tipo" width="10%">
                                    <h:outputText value="#{ protocolo.tipoProtocolo.nome }" />
                                </p:column>
                                <p:column headerText="Cliente" width="45%">
                                    <h:outputText value="#{ protocolo.cliente.nome }" />
                                </p:column>
                                <p:column headerText="Data" width="10%">
                                    <h:outputText value="#{ protocolo.dataCadastro }">
                                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="Valor" width="15%">
                                    <h:outputText value="#{ protocolo.valorTotalFermojupi + protocolo.valorTotalCartorio }">
                                        <f:convertNumber type="currency" locale="pt-BR" />
                                    </h:outputText>
                                </p:column>

                            </p:dataTable>
                        </p:fieldset>
                        <p:dialog header="Deseja realmente excluir?" widgetVar="dialogApagar" modal="true"
                                  closable="false" resizable="false" draggable="false" >
                            <div class="commandDialog">
                                <p:commandButton value="Sim" update=":pesquisarProtocoForm:protocolosDataTable"
                                                 oncomplete="dialogApagar.hide()" icon="ui-icon-check" actionListener="#{ managerPesquisarProtocolo.deletar() }" />
                                <p:commandButton value="Não" icon="ui-icon-close" oncomplete="dialogApagar.hide()" />
                            </div>
                        </p:dialog>


                    </div>
                </div>
            </h:form>
        </ui:define>      

    </ui:composition>

</html>
